<!-- 新增工作报表 -->

<template>
  <!-- https://element-plus.org/zh-CN/component/form.html#%E5%85%B8%E5%9E%8B%E8%A1%A8%E5%8D%95 -->
  <h2>新增报表</h2>
  <el-form :model="form" label-width="120px" id="form0">
    <div>
      <el-form-item label="报表名称" style="width: 30%;" id="form1">
      <el-input v-model="form.name" />
    </el-form-item>
    <el-form-item label="选择日期" id="form2">
      <el-col :span="11">
        <el-date-picker v-model="form.date1" type="date" placeholder="Pick a date" />
      </el-col>
    </el-form-item>
    </div>
    <el-form-item label="统计部门" id="form3">
      <el-checkbox-group v-model="form.type">
        <el-checkbox label="所有" name="type" />
        <el-checkbox label="工商管理部门" name="type" />
        <el-checkbox label="土地管理部门" name="type" />
        <el-checkbox label="行政许可部门" name="type" />
        <el-checkbox label="人事部门" name="type" />
        <el-checkbox label="社保部门" name="type" />
        <el-checkbox label="环保部门" name="type" />
      </el-checkbox-group>
    </el-form-item>
    <!-- -------------------- -->
    <el-form-item label="用途" id="form4">
      <el-select v-model="form.region" placeholder="请选择">
        <el-option label="例行存档" value="shanghai" />
        <el-option label="领导汇报" value="beijing" />
      </el-select>
    </el-form-item>
    <!-- ------------- -->
    <el-form-item label="附带图表" id="form5">
      <el-radio-group v-model="form.resource">
        <el-radio label="是" />
        <el-radio label="否" />
      </el-radio-group>
    </el-form-item>
    <!-- ----------- -->
    <slot></slot>
    <!-- ------------- -->
    <el-form-item label="备注"  >
      <el-input v-model="form.desc" type="textarea" id="form6" rows="6"  />
    </el-form-item>
    <!-- ----------- -->
    <el-form-item label="上传附件"  >
      <el-upload
    v-model:file-list="fileList"
    class="upload-demo"
    action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
    multiple
    :on-preview="handlePreview"
    :on-remove="handleRemove"
    :before-remove="beforeRemove"
    :limit="3"
    :on-exceed="handleExceed"
  >
    <el-button type="primary">选择文件</el-button>
    <template #tip>
      <div class="el-upload__tip">
        图片大小不超过 500KB.
      </div>
    </template>
  </el-upload>
    </el-form-item>
    
    <el-form-item id="form7">
      <el-button>取消</el-button>
      <el-button type="primary" @click="onSubmit">生成报表</el-button>
    </el-form-item>
    </el-form>

 
</template>

<script lang="ts" setup>
import { reactive,ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'

import type { UploadProps, UploadUserFile } from 'element-plus'



// do not use same name with ref
const form = reactive({
  name: '',
  region: '',
  date1: '',
  date2: '',
  delivery: false,
  type: [],
  resource: '',
  desc: '',
})

const onSubmit = () => {
  console.log('submit!')
}

/* 以下是文件上传 */
const fileList = ref<UploadUserFile[]>([
  /* {
    name: 'element-plus-logo.svg',
    url: 'https://element-plus.org/images/element-plus-logo.svg',
  },
  {
    name: 'element-plus-logo2.svg',
    url: 'https://element-plus.org/images/element-plus-logo.svg',
  }, */
])

const handleRemove: UploadProps['onRemove'] = (file, uploadFiles) => {
  console.log(file, uploadFiles)
}

const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
  console.log(uploadFile)
}

const handleExceed: UploadProps['onExceed'] = (files, uploadFiles) => {
  ElMessage.warning(
    `The limit is 3, you selected ${files.length} files this time, add up to ${
      files.length + uploadFiles.length
    } totally`
  )
}

const beforeRemove: UploadProps['beforeRemove'] = (uploadFile, uploadFiles) => {
  return ElMessageBox.confirm(
    `Cancel the transfert of ${uploadFile.name} ?`
  ).then(
    () => true,
    () => false
  )
}
</script>

<style scoped>
#form0{
  position: relative;

}
#form2{
  width: 300px;
  position: absolute;
  right: 600px;
  top: 0px;


}
/* #form5{
  width: 300px;
  position: absolute;
  right: 600px;
  top: 100px;


} */
#form7{
  width: 300px;
  position: absolute;
  right: 700px;
  bottom: -100px;


}



</style>